function uploadFile(
    {
        uploadApiUrl = "/File/uploadFile",
        maxCount = 1,
        maxSize = 0,
        accept = "",
        loading = true,
        otherParam = {},
        callback = Function()
    }
) {
    const $input = $(`<input type="file"  accept="${accept}" />`);
    if (maxCount) {
        $input.attr("multiple", "multiple");
    }
    $input.click();
    $input.on('change', function () {
        let $loadingWidget = null;

        const files = this.files;
        if (files.length > maxCount) {
            return callback({
                Code: -10000,
                Message: `最多上传${maxCount}个文件`
            });
        }

        if (loading) {
            $loadingWidget = $.loading("上传中")
        }

        const fileList = [];
        for (let i = 0; i < this.files.length; i++) {
            fileList.push(files[i]);
        }

        upload(fileList, [], res => {
            callback(res);
            if ($loadingWidget) {
                $loadingWidget.remove();
            }
        });
    });

    function upload(files, sucList = [], callback = Function()) {
        if (files == null || files.length === 0) {
            return callback(sucList.length === 0 ? {
                Code: -10000,
                Message: "没有任何文件被上传"
            } : {
                Code: 10000,
                Result: sucList
            });
        }

        const file = files.shift();
        const fileName = file.name;

        compressImage(file, maxSize, file => {
            if (!file) {
                return callback({
                    Code: -10000,
                    Message: `文件压缩失败`
                });
            }

            uploadApi(file, fileName, res => {
                if (res.Code !== 10000) {
                    return callback(res);
                }

                sucList.push(res.Result);
                upload(files, sucList, callback);
            })
        });

    }


    function compressImage(file, maxSize = null, callback = Function()) {
        const supportExtDict = ['png', 'jpg', 'jpeg', 'bmp'];
        const fileSize = file.size;
        maxSize *= 1204;
        if (!maxSize || fileSize <= maxSize) {
            return callback(file);
        }
        const fileName = file.name;
        const fileExt = fileName.slice(fileName.lastIndexOf(".") + 1).toLowerCase();

        if (supportExtDict.indexOf(fileExt) === -1) {
            return callback(file);
        }
        const image = new Image();
        image.src = (window.URL || window.webkitURL).createObjectURL(file);
        image.onload = () => {
            const rate = (fileSize - maxSize) / fileSize;
            const width = image.width * (1 - rate);
            const height = image.height * (1 - rate);
            const canvas = document.createElement('canvas');
            const ctx = canvas.getContext('2d');
            canvas.width = width;
            canvas.height = height;
            ctx.fillStyle = "#fff";
            ctx.fillRect(0, 0, canvas.width, canvas.height);
            ctx.drawImage(image, 0, 0, canvas.width, canvas.height);

            canvas.toBlob(blob => {
                return callback(blob);
            }, 'image/jpeg', 1);
        }
    }

    function uploadApi(file, fileName, callback = Function()) {
        const formData = new FormData();
        formData.append('file', file, fileName);
        if (otherParam) {
            Object.keys(otherParam).map(key => {
                formData.append(key, otherParam[key]);
            });
        }

        $.sApi({
            url: uploadApiUrl,
            data: formData,
            cache: false,
            processData: false,
            contentType: false
        }, callback);
    }
}